package com.sunshine.lnuplus.base

import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import androidx.fragment.app.Fragment
import com.sunshine.lnuplus.R
import kotlinx.android.synthetic.main.fragment_base.view.*

abstract class BaseFragment : Fragment(){

    private lateinit var activity: Activity
    private lateinit var baseView: View

    protected abstract fun setContent(): Int

    override fun onAttach(context: Context) {
        super.onAttach(context)
        activity = context as Activity
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        baseView = LayoutInflater.from(activity).inflate(R.layout.fragment_base, container, false)
        val view = LayoutInflater.from(activity).inflate(setContent(), null, false)

        view.layoutParams = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)
        baseView.base_container.addView(view)
        return baseView
    }

    fun getTimetableTheme(): Int? {
        if(context!!.getSharedPreferences("com.sunshine.lnuplus_preferences", Context.MODE_PRIVATE).getBoolean("night", false)) return 1
        return context?.getSharedPreferences("com.sunshine.lnuplus_preferences", Context.MODE_PRIVATE)?.getInt("timetable_theme", 3)
    }

}